<?php

class FP_Auth_Adapter implements Zend_Auth_Adapter_Interface {

	protected $user     = null;
	protected $password = null;

	public function __construct($pUsername, $pPassword){
	    $Users = FP_Application::classFactory('Users');
	    $this->user = $Users->fetchByUsername($pUsername, true);
	    $this->password = $pPassword;
	}

	public function authenticate(){
	    if ($this->user){
		if ($this->user->isActive()){

		    if ($this->user->authenticate($this->password)){
			return new Zend_Auth_Result(Zend_Auth_Result::SUCCESS, $this->user);
		    } else
			return new Zend_Auth_Result(Zend_Auth_Result::FAILURE_CREDENTIAL_INVALID, null);
		} else
		    return new Zend_Auth_Result(Zend_Auth_Result::FAILURE, null);
	    } else
		return new Zend_Auth_Result(Zend_Auth_Result::FAILURE_IDENTITY_NOT_FOUND, null);
	}

}

?>